# -*- coding: utf-8 -*-
'''
Created on 2013/8/10

@author: Jason
'''
from django.core.mail.message import EmailMultiAlternatives
from django.utils.translation import ugettext as _
from users.views import maskPid
import logging

def sendMail(subject, fromAddr, to_list, msg_text, msg_html):
    logging.info('executing sendMail')
    
    msg = EmailMultiAlternatives(subject, msg_text, fromAddr, to_list)
    logging.info('create EmailMultiAlternatives')
    
    msg.attach_alternative(msg_html, "text/html")
    logging.info('attach msg_html to alternative')
    
    msg.send()
    logging.info('send message')

def getSucceedTableHtml(participant):
    
    dGender = _(participant.gender) 
    
    dPid = maskPid(participant.pid)
    
    if participant.nationality == 'TW':
        dNationality = _('Taiwan')
    else:
        dNationality = participant.nationality
    
    if participant.estimateTime == 'unknown':
        dEstimateTime = _('unknown')
    elif participant.estimateTime == 'below 18:00':
        dEstimateTime = _('below') + ' 18:00'
    elif participant.estimateTime == 'over 25:00':
        dEstimateTime = _('over') + ' 25:00'
    else:
        dEstimateTime = participant.estimateTime
        
    '''background-color:#f9f9f9;'''
    result = u'''
                <table class="table table-striped">
                        <thead>
                        </thead>
                        <tbody>
                            <tr>
                                <td style="font-weight:bold;">'''+_("Serial number")+'''</td>
                                <td style="text-color:#b94a48;"><strong>'''+participant.signupKey+'''</strong></td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">'''+_("Name")+'''</td>
                                <td>'''+participant.name+'''</td>
                                <td style="font-weight:bold">'''+ _("Gender")+'''</td>
                                <td>'''+dGender+'''</td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">'''+_("Personal id")+'''</td>
                                <td>'''+dPid+'''</td>
                                <td style="font-weight:bold">'''+_("Birthday")+'''</td>
                                <td>'''+participant.bday+'''</td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">'''+_("Phone Number")+'''</td>
                                <td>'''+participant.phoneNum+'''</td>
                                <td style="font-weight:bold">'''+_("Nationality")+'''</td>
                                <td>'''+dNationality+'''</td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Email</td>
                                <td>'''+participant.email+'''</td>
                                <td style="font-weight:bold">'''+_("Estimate time")+'''</td>
                                <td>'''+dEstimateTime+'''</td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">'''+_("Emergency contact person")+'''</td>
                                <td>'''+participant.emgcyContact+'''</td>
                                <td style="font-weight:bold">'''+_("Emergency contact person's phone number")+'''</td>
                                <td>'''+participant.emgcyContPhone+'''</td>
                            </tr>
                        </tbody>
                    </table>
                '''
    return result